{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_pattern_search:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pattern Search (Hooke and Jeeves)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "An implementation of well-known Hooke and Jeeves Pattern Search <cite data-cite=\"pattern_search\"></cite> for single-objective optimization which makes use of *exploration* and *pattern* moves in an alternating manner. \n",
    "For now, we like to refer to [Wikipedia](https://en.wikipedia.org/wiki/Pattern_search_(optimization)) for more information such as pseudo code and visualizations in the search space."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "code": "algorithms/usage_pattern_search.py"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best solution found: \n",
      "X = [-9.27771855e-14 -2.97851640e-14 -1.26925499e-15  8.91408665e-14\n",
      " -1.19684856e-14 -6.66560896e-14  8.11832539e-14 -8.68501150e-14\n",
      "  6.93977971e-14 -8.47269999e-14 -1.22541465e-13  1.15618649e-13\n",
      "  5.49523346e-14  4.71786414e-14 -8.61731588e-14 -6.07986908e-14\n",
      "  1.00688146e-13 -3.36770408e-14  3.38081544e-14  8.86496611e-14\n",
      " -5.67424639e-14  7.34497267e-14 -7.59578144e-14 -2.42403699e-14\n",
      "  3.69602818e-14 -6.67519772e-14  4.79715018e-14  2.70083653e-14\n",
      " -1.01982970e-13 -8.13052041e-14]\n",
      "F = [2.88213897e-13]\n"
     ]
    }
   ],
   "source": [
    "from pymoo.algorithms.so_pattern_search import PatternSearch\n",
    "from pymoo.factory import get_problem\n",
    "from pymoo.optimize import minimize\n",
    "\n",
    "problem = get_problem(\"ackley\", n_var=30)\n",
    "\n",
    "algorithm = PatternSearch()\n",
    "\n",
    "res = minimize(problem,\n",
    "               algorithm,\n",
    "               seed=1,\n",
    "               verbose=False)\n",
    "\n",
    "print(\"Best solution found: \\nX = %s\\nF = %s\" % (res.X, res.F))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### API"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. autoclass:: pymoo.algorithms.so_pattern_search.PatternSearch\n",
    "    :noindex:"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
